$(document).ready(function() {	
	$('.tipsy').tipsy({gravity: 'w'});// nw | n | ne | w | e | sw | s | se --- http://onehackoranother.com/projects/jquery/tipsy/	
	$("#frmEdit").validate({
		errorClass		: 'errorMessage',
		errorElement	: 'span',
		onfocusout		: false,
		onkeyup			: false,
		rules: {
			pcategoryid:{
				required				: true,
				min						: 1
			},	
			psubcategoryid:{
				required				: true,
				min						: 1
			},	
			pname:{
				required				: true,
				minlength				: 5
			},
			pimage: {			
				validateImgRequired		: true,
				validateImgFormat		: true,
				validateImgSize			: true
			},			
			pcontent: {
				validateContentRequired	: true,
				validateContentMinlength: true
			}
		},
		messages: {	
			pcategoryid:{
				required				: cate_required,
				min						: cate_required
			},	
			psubcategoryid:{
				required				: subcate_required,
				min						: subcate_required
			},	
			pname:{
				required				: name_required,
				minlength				: name_minlength
			},
			pimage: {
				validateImgRequired		: image_required,
				validateImgFormat		: image_format,
				validateImgSize			: image_size
			},			
			pcontent: {
				validateContentRequired	: content_required,
				validateContentMinlength: content_minlength
			}
		},
		errorPlacement: function(label, element) {
			var id = element.attr('id');	
			var id = element.attr('id');	
			if(id == "pimage") {
				label.insertAfter($('#simage'));					
			} else if(id == "pcategoryid") {
				label.insertAfter($('#selcate'));					
			}else if(id == "pcontent") {			
				label.insertAfter($('#pcontent___Frame'));
			} else {
				label.insertAfter($('#' + id));			
			}

			
		}				 
	});
	$.validator.addMethod('validateImgRequired',function(){
		var strLinkImage = $('#pimage').val();
		var strOldLinkImage = $('#pimage_old').val();
		if(strOldLinkImage == "" && strLinkImage == "")
			return false;
		return true;
	});
	$.validator.addMethod('validateImgFormat', function() {
		var strLinkImage = $('#pimage').val();
		var strOldLinkImage = $('#pimage_old').val();
		if(strLinkImage == "" && strOldLinkImage == "") {
			return false;
		} else if(strLinkImage == "" && strOldLinkImage != "") {
			return true;
		}
		return validateImage(strLinkImage);
	});
	$.validator.addMethod('validateImgSize', function() {
		var strLinkImage = $('#pimage').val();
		var strOldLinkImage = $('#pimage_old').val();
		if(strLinkImage == "" && strOldLinkImage == "") {
			return false;
		} else if(strLinkImage == "" && strOldLinkImage != "") {
			return true;
		}
		return validateImgSize("pimage");
	});	
	$.validator.addMethod('validateContentRequired',function(){
		var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
		var strContent		= stripTags(oEditorContent.GetXHTML( true ), 1);		
		if(strContent == '')
			return false;		
		return true;												 
	});
	$.validator.addMethod('validateContentMinlength',function(){
		var oEditorContent 	= FCKeditorAPI.GetInstance('pcontent') ;
		var strContent		= stripTags(oEditorContent.GetXHTML( true ), 1);		
		if(strContent != '' && strContent.length < 20)
			return false;		
		return true;												 
	});	
});
function deleteImage(intVal) {
	if(confirm(confirm_delete_img) == true) {		
		$.getJSON(				
		HOST_VFRIEND + 'ajax/news?act=3&newsid='+intVal+'&callback=?',		
			function(response) {					
				if(response['error'] == 0) {						
					showUIMessage(response['msg']);
					setTimeout(function(){
						$('#imgDemo').hide();	
					},800);					
				} else {
					alert(response['msg']);
				}
			}
		);
	} 
}
onMouseOverForImg = function() {
	$('#rowImg').show();
}
onMouseOutForImg = function() {
	$('#rowImg').hide();
}

loadSub = function(intValue, strDiv) {
	$.getJSON(
		HOST_VFRIEND + 'ajax/subcate?type=10&parentid=' + intValue + '&callback=?',		
		function(response) {							
			$('#'+strDiv).html(response['data']);
		}
	);
}

//initSub = function
